package controllers

import dao.{GermDao, MapDao, NewsDao}
import javax.inject.Inject
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.concurrent.ExecutionContext

class NewsController  @Inject()()(newsDao: NewsDao ,cc: ControllerComponents)
                               (implicit exec: ExecutionContext) extends AbstractController(cc){

  def getAllNews = Action.async { implicit request =>
    newsDao.getAllNews.map { x =>
      val row = x.sortBy(_.createdate).reverse.map { y =>
        Json.obj("id" -> y.id, "news" -> y.title, "date" -> y.createdate)
      }
      Ok(Json.toJson(row))
    }
  }

}
